$(document).ready(function() {
});


// 重启被点击  重启矿机
$('#restart').click(function () {
    console.log("重启矿机1")
    var snIP = $("#snIP").val();

    $.ajax({
        type: "post",
        url: basePath + "/worker/ajaxWorkerRestart",
        data: {"snip": snIP},
        dataType: "json",
        success: function (res) {
            console.log(res)
            if(res.bizSuccess){
                // $("#warning-header-modal").removeClass("show").css("display", "none");
                // window.location.reload();
                sucMsg("重启成功，请稍后查看");
            }
            else{
                errMsg(res.errorMsg);
            }
        }
    });
})

/** 刷新 （获取最新的数据） 监听*/
$('#refresh').click(function () {
    console.log("刷新矿机，，，监听");
    var snIP = $("#snIP").val();
    $.ajax({
        type : "post",
        url : basePath + "/worker/ajaxRefreshWorker",
        data : { "snip":snIP},
        dataType: "json",
        success: function (res) {
            if(res.bizSuccess){
                ajaxWorkerRefresh();
                sucMsg("刷新成功");
            }
            else{
                errMsg(res.errorMsg)
            }
        }
    });
});

/** 刷新 矿机状态信息*/
function ajaxWorkerRefresh() {
    console.log("刷新矿机，，，监听");
    var snIP = $("#snIP").val();
    $.ajax({
        type : "post",
        url : basePath + "/worker/ajaxWorkerDetails",
        data : { "snip":snIP},
        dataType: "html",
        success: function (txt) {
            $("#ajaxWorkerState").html(txt);
        }
    });
};


/** 修改矿机地址*/
$('#editIPAddr').click(function () {
    sucMsg("修改矿机IP地址信息，需要完善");

})

    /** 修改矿机地址*/
    function ajaxWorkerIpAddressModify(){
        var ipAddre = $("#snIP").val();
        var hostName = $("#hostName").val();
        var type= $("#type  option:selected").text();;                 // 类型（静态）
        // var type= "123";                 // 类型（静态）
        var address= $("#address").val();           // IP地址
        var mask= $("#mask").val();                 // 掩码
        var gateway= $("#gateway").val();           // 网关
        var dns= $("#dns").val();                   // DNS

        $.ajax({
            type : "post",
            url : basePath + "/worker/ajaxWorkerIpAddressModify",
            data : {"hostName":hostName,"snip": ipAddre,"type":type,"address":address,"mask":mask,"gateway":gateway,"dns":dns},
            dataType: "json",
            success : function(txt){
                console.log("跳转页面")
                $("#signup-modal").click();
            }
        });
    }

    /** 配置矿池 */
    $('#modifyMineralKeep').click(function () {
        var ipAddre = $("#snIP").val();
        var minePool1= $("#poolUrl1").val();           // 矿池1
        var account1= $("#poolUser1").val();             // 账号1
        var password1= $("#poolPsw1").val();           // 密码1

        var minePool2= $("#poolUrl2").val();           // 矿池2
        var account2= $("#poolUser2").val();             // 账号2
        var password2= $("#poolPsw2").val();           // 密码2

        var minePool3= $("#poolUrl3").val();           // 矿池3
        var account3= $("#poolUser3").val();             // 账号3
        var password3= $("#poolPsw3").val();           // 密码3

        $.ajax({
            type : "post",
            url : basePath + "/worker/ajaxWorkerMinePoolModify",
            data : {"snip": ipAddre,"minePool1":minePool1,"account1":account1,"password1":password1,"minePool2":minePool2,"account2":account2,"password2":password2,"minePool3":minePool3,"account3":account3,"password3":password3},
            dataType: "json",
            success : function(txt){
                sucMsg("配置矿池成功");
                console.log("跳转页面")
                $("#configMineral").click();
            }
        });
    })